//
//  KATabVC.swift
//  kano
//
//  Created by Sophia on 2024/8/19.
//

import UIKit


class KATabVC: UITabBarController {
    

//    static var shared = KATabVC()

    init() {
        super.init(nibName: nil, bundle: nil)
    }

    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()
        UITabBar.appearance().shadowImage = UIImage()
        UITabBar.appearance().backgroundImage = self.ka_image(with: .colorFFF)
        UITabBar.appearance().backgroundColor = .colorFFF
        UITabBar.appearance().barTintColor = .clear
    }
    
    func ka_addChildVC(_ title: String,
                  _ image: String,
                  _ selectedImage: String,
                  _ child: UIViewController.Type) {
        let vc = child.init()
        vc.title = title
        vc.tabBarItem.image = UIImage(named: image)?.withRenderingMode(.alwaysOriginal)
        vc.tabBarItem.selectedImage = UIImage(named: selectedImage)?.withRenderingMode(.alwaysOriginal)
        vc.tabBarItem.setTitleTextAttributes([.foregroundColor : UIColor.color8A8891], for: .normal)
        vc.tabBarItem.setTitleTextAttributes([.foregroundColor : UIColor.themeColor], for: .selected)
        let navVC = KANavigationVC.init(rootViewController: vc)

        addChild(navVC)
    }

    func ka_image(with color: UIColor) -> UIImage {
        let rect = CGRect(x: 0, y: 0, width: 1, height: 1)
        UIGraphicsBeginImageContextWithOptions(rect.size, false, 0)
        color.setFill()
        UIRectFill(rect)
        let image: UIImage = UIGraphicsGetImageFromCurrentImageContext()!
        UIGraphicsEndImageContext()
        return image
    }
}
